from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-02 14:06:14.377515
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 02, Feb, 2022
Time: 14:06:19
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9439
Nobs: 555.000 HQIC: -48.3707
Log likelihood: 6501.19 FPE: 7.48305e-22
AIC: -48.6443 Det(Omega_mle): 6.37205e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350156 0.069604 5.031 0.000
L1.Burgenland 0.107016 0.042262 2.532 0.011
L1.Kärnten -0.110597 0.021958 -5.037 0.000
L1.Niederösterreich 0.195539 0.088382 2.212 0.027
L1.Oberösterreich 0.132860 0.087307 1.522 0.128
L1.Salzburg 0.254005 0.044678 5.685 0.000
L1.Steiermark 0.035937 0.058925 0.610 0.542
L1.Tirol 0.097857 0.047574 2.057 0.040
L1.Vorarlberg -0.071799 0.042041 -1.708 0.088
L1.Wien 0.016524 0.077738 0.213 0.832
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054064 0.150695 0.359 0.720
L1.Burgenland -0.041425 0.091500 -0.453 0.651
L1.Kärnten 0.040504 0.047541 0.852 0.394
L1.Niederösterreich -0.202942 0.191351 -1.061 0.289
L1.Oberösterreich 0.454203 0.189024 2.403 0.016
L1.Salzburg 0.283638 0.096731 2.932 0.003
L1.Steiermark 0.115458 0.127575 0.905 0.365
L1.Tirol 0.306002 0.103000 2.971 0.003
L1.Vorarlberg 0.023142 0.091021 0.254 0.799
L1.Wien -0.023197 0.168307 -0.138 0.890
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195551 0.035382 5.527 0.000
L1.Burgenland 0.091158 0.021483 4.243 0.000
L1.Kärnten -0.007388 0.011162 -0.662 0.508
L1.Niederösterreich 0.235592 0.044928 5.244 0.000
L1.Oberösterreich 0.168750 0.044381 3.802 0.000
L1.Salzburg 0.038389 0.022712 1.690 0.091
L1.Steiermark 0.025898 0.029954 0.865 0.387
L1.Tirol 0.080702 0.024184 3.337 0.001
L1.Vorarlberg 0.055317 0.021371 2.588 0.010
L1.Wien 0.117796 0.039517 2.981 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118439 0.035527 3.334 0.001
L1.Burgenland 0.043774 0.021571 2.029 0.042
L1.Kärnten -0.013782 0.011208 -1.230 0.219
L1.Niederösterreich 0.171294 0.045112 3.797 0.000
L1.Oberösterreich 0.335802 0.044563 7.535 0.000
L1.Salzburg 0.099644 0.022805 4.369 0.000
L1.Steiermark 0.109801 0.030076 3.651 0.000
L1.Tirol 0.090328 0.024283 3.720 0.000
L1.Vorarlberg 0.060681 0.021459 2.828 0.005
L1.Wien -0.016195 0.039679 -0.408 0.683
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125781 0.067006 1.877 0.060
L1.Burgenland -0.047941 0.040685 -1.178 0.239
L1.Kärnten -0.045497 0.021139 -2.152 0.031
L1.Niederösterreich 0.140905 0.085083 1.656 0.098
L1.Oberösterreich 0.166453 0.084048 1.980 0.048
L1.Salzburg 0.283941 0.043011 6.602 0.000
L1.Steiermark 0.058453 0.056726 1.030 0.303
L1.Tirol 0.155443 0.045798 3.394 0.001
L1.Vorarlberg 0.093991 0.040472 2.322 0.020
L1.Wien 0.071879 0.074837 0.960 0.337
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080801 0.052280 1.546 0.122
L1.Burgenland 0.024374 0.031744 0.768 0.443
L1.Kärnten 0.053362 0.016493 3.235 0.001
L1.Niederösterreich 0.191071 0.066385 2.878 0.004
L1.Oberösterreich 0.330999 0.065578 5.047 0.000
L1.Salzburg 0.033038 0.033559 0.984 0.325
L1.Steiermark 0.004259 0.044260 0.096 0.923
L1.Tirol 0.119646 0.035734 3.348 0.001
L1.Vorarlberg 0.066203 0.031578 2.097 0.036
L1.Wien 0.098177 0.058391 1.681 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172021 0.063331 2.716 0.007
L1.Burgenland 0.002624 0.038453 0.068 0.946
L1.Kärnten -0.065571 0.019979 -3.282 0.001
L1.Niederösterreich -0.106498 0.080416 -1.324 0.185
L1.Oberösterreich 0.212215 0.079439 2.671 0.008
L1.Salzburg 0.053766 0.040652 1.323 0.186
L1.Steiermark 0.249138 0.053614 4.647 0.000
L1.Tirol 0.498348 0.043287 11.513 0.000
L1.Vorarlberg 0.064568 0.038252 1.688 0.091
L1.Wien -0.077230 0.070732 -1.092 0.275
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156236 0.069896 2.235 0.025
L1.Burgenland -0.004228 0.042439 -0.100 0.921
L1.Kärnten 0.062159 0.022051 2.819 0.005
L1.Niederösterreich 0.182147 0.088752 2.052 0.040
L1.Oberösterreich -0.066880 0.087673 -0.763 0.446
L1.Salzburg 0.205289 0.044866 4.576 0.000
L1.Steiermark 0.139471 0.059172 2.357 0.018
L1.Tirol 0.056146 0.047774 1.175 0.240
L1.Vorarlberg 0.142882 0.042217 3.384 0.001
L1.Wien 0.130119 0.078064 1.667 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395315 0.040788 9.692 0.000
L1.Burgenland -0.002757 0.024766 -0.111 0.911
L1.Kärnten -0.020664 0.012868 -1.606 0.108
L1.Niederösterreich 0.202683 0.051792 3.913 0.000
L1.Oberösterreich 0.240074 0.051163 4.692 0.000
L1.Salzburg 0.033814 0.026182 1.291 0.197
L1.Steiermark -0.018025 0.034531 -0.522 0.602
L1.Tirol 0.087166 0.027879 3.127 0.002
L1.Vorarlberg 0.050953 0.024636 2.068 0.039
L1.Wien 0.034990 0.045555 0.768 0.442
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034869 0.103995 0.167587 0.133418 0.095462 0.078264 0.028923 0.211388
Kärnten 0.034869 1.000000 -0.025678 0.132885 0.046770 0.085733 0.444173 -0.068272 0.093293
Niederösterreich 0.103995 -0.025678 1.000000 0.310710 0.124808 0.269439 0.064642 0.156090 0.281308
Oberösterreich 0.167587 0.132885 0.310710 1.000000 0.214938 0.294086 0.166631 0.133472 0.235643
Salzburg 0.133418 0.046770 0.124808 0.214938 1.000000 0.124599 0.088592 0.103404 0.127513
Steiermark 0.095462 0.085733 0.269439 0.294086 0.124599 1.000000 0.131293 0.105188 0.029330
Tirol 0.078264 0.444173 0.064642 0.166631 0.088592 0.131293 1.000000 0.064054 0.151255
Vorarlberg 0.028923 -0.068272 0.156090 0.133472 0.103404 0.105188 0.064054 1.000000 -0.005034
Wien 0.211388 0.093293 0.281308 0.235643 0.127513 0.029330 0.151255 -0.005034 1.000000